Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

planner: add maybe good heuristics for index selection #26850

Closed

Conversation

xuyifangreeneyes
Copy link
Contributor

What problem does this PR solve?

Issue Number: close #xxx

Problem Summary:

What is changed and how it works?

When SQL has order by pk limit n pattern, and one index path only has point ranges and its CountAfterAccess is small enough, we directly choose the index rather than pk. Since the heuristic rule is not always good, we introduce a global/session variable tidb_enable_maybe_good_heuristics and only apply the rule when the switch turns on. When executing EXPLAIN, TiDB will output a NOTE level warning if some path matches the maybe good heuristic rule.

Check List

Tests

  • Unit test
  • Integration test
  • Manual test (add detailed scripts or steps below)
  • No code

Side effects

  • Performance regression: Consumes more CPU
  • Performance regression: Consumes more Memory
  • Breaking backward compatibility

Documentation

  • Affects user behaviors
  • Contains syntax changes
  • Contains variable changes
  • Contains experimental features
  • Changes MySQL compatibility

Release note

introduce maybe good heuristics for index selection

@ti-chi-bot
Copy link
Member

[REVIEW NOTIFICATION]

This pull request has not been approved.

To complete the pull request process, please ask the reviewers in the list to review by filling /cc @reviewer in the comment.
After your PR has acquired the required number of LGTMs, you can assign this pull request to the committer in the list by filling /assign @committer in the comment to help you merge this pull request.

The full list of commands accepted by this bot can be found here.

Reviewer can indicate their review by submitting an approval review.
Reviewer can cancel approval by submitting a request changes review.

@ti-chi-bot ti-chi-bot added release-note Denotes a PR that will be considered when it comes time to generate release notes. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. labels Aug 3, 2021
@xuyifangreeneyes
Copy link
Contributor Author

/sig planner

@ti-chi-bot ti-chi-bot added the sig/planner SIG: Planner label Aug 3, 2021
@github-actions github-actions bot added the sig/execution SIG execution label Aug 3, 2021
@ti-chi-bot ti-chi-bot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Aug 8, 2021
@ti-chi-bot ti-chi-bot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. labels Aug 9, 2021
@xuyifangreeneyes
Copy link
Contributor Author

/cc @winoros

@ti-chi-bot ti-chi-bot requested a review from winoros August 9, 2021 02:44
@xuyifangreeneyes
Copy link
Contributor Author

Since #27123 can also make the optimizer choose index rather than pk for the situations like where index_col = ... order by pk limit n, the pr can be closed.

@xuyifangreeneyes xuyifangreeneyes deleted the maybe-good-heuristics branch October 30, 2021 05:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
release-note Denotes a PR that will be considered when it comes time to generate release notes. sig/execution SIG execution sig/planner SIG: Planner size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants